<!-- 表单弹窗 -->
<form id="notice-form" lay-filter="notice-form" class="layui-form model-form" style="overflow:auto; height:500px;width:90%;">
    <input name="id" type="hidden"/>

 		    <div class="layui-form-item">
        <label class="layui-form-label">类型 </label>
        <div class="layui-input-block">
                <input type="radio" name="type" value="1" title="通知" checked/>
                <input type="radio" name="type" value="2" title="公告"/>
                <input type="radio" name="type" value="3" title="推广"/>
        </div>
    </div>

 		    <div class="layui-form-item">
        <label class="layui-form-label">图片</label>
        <div class="layui-input-block">
<!--            <input name="image" placeholder="请输入图片" type="text" class="layui-input" maxlength="20"  id="image"-->
<!--                   lay-verify="required" required/>-->

            <input type="hidden" name="image"   id="uploadPath" class="layui-input"     />
            <img id="uploadimg" src="" width="50" />

            <button type="button" class="layui-btn"  id="uploadUrl"   lay-filter="uploadFile">
                <i class="layui-icon">&#xe67c;</i>选择图片
            </button>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input name="title" placeholder="请输入标题" type="text" class="layui-input" maxlength="20"  id="title"
                   lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">概述</label>
        <div class="layui-input-block">
            <input name="summary" placeholder="请输入概述" type="text" class="layui-input"    id="summary"
                   />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">正文</label>
        <div class="layui-input-block">
            <textarea name="content" placeholder="请输入正文"   class="layui-textarea"   id="content"   />
        </div>
    </div>


     <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="user-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'admin', 'form', 'formSelects','layedit','config','upload'], function () {
        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;
        var formSelects = layui.formSelects;
        var   config = layui.config;
        var layedit = layui.layedit;
        var upload = layui.upload;





var notice = admin.getTempData('t_notice');
           if (notice.method=="update"){
        	form.val('notice-form', notice);

        }
        form.render();
        // 表单提交事件
        form.on('submit(user-form-submit)', function (data) {
             layer.load(2);
            
            admin.req('sys/notice/'+notice.method, JSON.stringify(data.field), function (data) {
                layer.closeAll('loading');
                if (data.code == 0) {
                    layer.msg(data.msg, {icon: 1, time: 500});
                    admin.finishPopupCenter();
                } else {
                    layer.msg(data.msg, {icon: 2, time: 500});
                }
            }, "post");  
            return false;
        });

        //创建一个上传组件 remarkuploadUrl
        upload.render({
            elem: '#uploadUrl'
            ,url:config.base_server+'file/uploadFile'
            ,accept: "images"
            ,before: function(o){
                console.log(o)
            }
            ,done: function(res, index, upload){ //上传后的回调
                if(res.code==0){
                    $('#uploadimg').attr("src", res.data.url);
                    $('#uploadPath').val(res.data.url);
                }
            }
        });



    });
</script>
